package com.longrise.bymodule.page.byzp;

import android.text.TextUtils;
import android.webkit.JavascriptInterface;

import com.longrise.common.base.RxManager;
import com.longrise.common.base.web.BaseWebActivity;
import com.longrise.common.base.web.BaseWebBridge;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 2017/11/24.
 * 保易智评的webBridge
 */

class BYZPwebBridge extends BaseWebBridge {


    public BYZPwebBridge(BaseWebActivity activity, RxManager rxManager) {
        super(activity, rxManager);
    }

    @JavascriptInterface
    public void confirm(final String url) {
        if (!TextUtils.isEmpty(url)) {
            Disposable subscribe = Observable.create(new ObservableOnSubscribe<String>() {
                @Override
                public void subscribe(ObservableEmitter<String> e) throws Exception {
                    e.onNext(url);
                    e.onComplete();
                }
            }).observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Consumer<String>() {
                        @Override
                        public void accept(String s) throws Exception {
                            ((BYZPActivity) mActivity).linkTo(s);
                        }
                    });
            mRxManager.addDisposable(subscribe);
        }
    }
}
